<template>
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
      <el-form-item label="姓名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入姓名"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!--<el-form-item label="报工时间">
        <el-date-picker v-model="dateRange"
                        style="display: flex;"
                        value-format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-popconfirm title="确认选择批量质检的数据项？" @confirm="handleZhijianAll({})">
          <el-button slot="reference" type="success" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                     v-hasPermi="['develop:GoodsSaledoGongxuUserMoney:remove']">批量质检合格</el-button>
        </el-popconfirm>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" @sort-change="handleSortChange" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column sortable label="项目编号" align="center" prop="projectCode"/>
      <el-table-column sortable label="产品编号" align="center" prop="goodsCode"/>
      <el-table-column sortable label="产品名称" align="center" prop="goodsName"/>
      <el-table-column sortable label="产品型号" align="center" prop="goodsModel"/>
      <el-table-column sortable label="工序名称" align="center" prop="name"/>
      <el-table-column sortable align="center" label="生产产品名称" prop="gongxuName" />
      <el-table-column sortable align="center" label="生产产品型号" prop="gongxuModel" />
      <el-table-column sortable label="姓名" align="center" prop="userName"/>
      <el-table-column sortable label="报工时间" align="center" prop="doTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.doTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报工数量" align="center" prop="count"/>
      <el-table-column label="单价" align="center" prop="money"/>
      <el-table-column label="所用时间（小时）" align="center" prop="hour"/>
      <el-table-column label="合格数量" align="center" prop="successCount"/>
      <el-table-column label="不合格数量" align="center" prop="errorCount"/>
      <el-table-column label="合格总价" align="center" prop="allMoney"/>
      <el-table-column label="合格率(%)" align="center" prop="successLv"/>
      <el-table-column align="center" label="状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.baogong_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="质检日期" align="center" prop="zhijianDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zhijianDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="质检人" align="center" prop="zhijianUser"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['develop:GoodsSaledoGongxuUserMoney:edit']">修改报工</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="zhijian(scope.row)" v-hasPermi="['develop:GoodsSaledoGongxuUserMoney:edit']">质检</el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:GoodsSaledoGongxuUserMoney:remove']">删除报工</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <goodsSaledoGongxuUserMoney-form ref="form" @ok="getList"></goodsSaledoGongxuUserMoney-form>
    <zhijianGongxu-form ref="zhijianForm" @ok="getList"></zhijianGongxu-form>
    </el-dialog>
</template>

<script>
  import { deleteAction, getAction } from '@/api/manage'
  import GoodsSaledoGongxuUserMoneyForm from '@/views/develop/goodsSaledoGongxuUserMoney/module/GoodsSaledoGongxuUserMoneyForm'
  import ZhijianGongxuForm from '@/views/develop/goodsSaledoGongxuUserMoney/module/ZhijianGongxuForm'
  import { list } from "@/api/develop/goodsSaledoGongxuUserMoney";

  export default {
    name: "GoodsSaledoGongxuUserMoneyList",
    dicts: ['baogong_status'],
    components: {
      GoodsSaledoGongxuUserMoneyForm,
      ZhijianGongxuForm,
    },
    data() {
      return {
        title:'报工明细',
        // 遮罩层
        loading: true,
        open: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 报工列表格数据
        dataList: [],
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          xuhao: null,
          doTime: null,
          userId: null,
          userName: null,
          money: null,
          count: null,
          allMoney: null,
          parentId: null,
          successCount: null,
          errorCount: null,
          successLv: null,
          status: null,
          zhijianDate: null,
          zhijianUser: null,
          zhijianId: null
        },
        url: {
          //list:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/list',
          list:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/listAndParent',
          removeUpdate:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/removeUpdate/',
          export:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/export',
          zhijianAllUpdate:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/zhijianAllUpdate/',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      //this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed () {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      /** 排序触发事件 */
		handleSortChange(column, prop, order) {
		  this.queryParams.orderByColumn = column.prop;
		  this.queryParams.isAsc = column.order;
		  this.handleQuery();
		},
      baogongMingxigShow(row){
        this.open = true;
        this.queryParams.parentId=row.id;
        this.getList();
      },
      /** 查询报工列列表 */
      getList() {
        this.loading = true;
        list(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          //getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight () {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.form.handleUpdate(row);
      },
      zhijian(row) {
        this.$refs.zhijianForm.zhijianShow(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.removeUpdate, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(this.url.export, {
          ...this.queryParams
        }, `goodsSaledoGongxuUserMoney_${new Date().getTime()}.xlsx`)
      },
      handleZhijianAll(){
        const ids = this.ids;
        deleteAction(this.url.zhijianAllUpdate, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("批量质检成功！");
        }).catch(() => {});
      },
    }
  };
</script>
